package net.wanho;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.Collections;

public class CodeGenerator {

    // 项目路径
    private static final String projectPath = "C:\\Users\\Administrator\\IdeaProjects\\fullstack126\\springboot04-generator";

    public static void main(String[] args) throws Exception {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/vip", "root", "root")
                .globalConfig(builder -> {
                    builder.author("") // 设置作者
                            .enableSwagger() // 开启swagger模式
                            .disableOpenDir() // 关闭打开目录
                            .outputDir(projectPath + "/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("net.wanho") // 设置父包名
                            .entity("po")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, projectPath + "/src/main/resources/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder ->
                        builder.addTablePrefix("t_", "sys_") // 设置过滤表前缀
                                .entityBuilder() // entity配置
                                    .enableLombok()
                                    .logicDeleteColumnName("is_deleted")
                                    .addTableFills(new Column("create_time", FieldFill.INSERT))
                                    .addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE))
                                    .enableFileOverride()
                                .mapperBuilder() // mapper配置
                                    .enableMapperAnnotation()
                                    .enableBaseResultMap()
                                    .enableBaseColumnList()
                                    .enableFileOverride()
                                .serviceBuilder() // service配置
                                    .formatServiceFileName("%sService")
                                    .enableFileOverride()
                                .controllerBuilder() // controller配置
                                    .enableHyphenStyle() // 开启驼峰转连字符
                                    .enableRestStyle() // 开启生成@RestController控制器
                                    .enableFileOverride()
                )
                .execute();
    }

}